// https://umijs.org/config/
import { defineConfig, utils } from 'umi';
import defaultSettings from './defaultSettings';
import proxy from './proxy';
import webpackPlugin from './plugin.config';
const { winPath } = utils; // preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。

const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV, GA_KEY } = process.env;
export default defineConfig({
  hash: true,
  antd: {},
  analytics: GA_KEY
    ? {
        ga: GA_KEY,
      }
    : false,
  dva: {
    hmr: true,
  },
  locale: {
    // default zh-CN
    default: 'zh-CN',
    // default true, when it is true, will use `navigator.language` overwrite default
    antd: true,
    baseNavigator: true,
  },
  dynamicImport: {
    loading: '@/components/PageLoading/index',
  },
  targets: {
    ie: 11,
  },
  // umi routes: https://umijs.org/docs/routing
  routes: [
    {
      path: '/',
      component: '../layouts/BlankLayout',
      routes: [
        {
          path: '/user',
          component: '../layouts/UserLayout',
          routes: [
            {
              path: '/user',
              redirect: '/user/login',
            },
            {
              name: 'login',
              path: '/user/login',
              component: './user/login',
            },
            {
              name: 'register-result',
              path: '/user/register-result',
              component: './user/register-result',
            },
            {
              name: 'register',
              path: '/user/register',
              component: './user/register',
            },
            {
              component: '404',
            },
          ],
        },
        {
          path: '/',
          component: '../layouts/BasicLayout',
          Routes: ['src/pages/Authorized'],
          authority: ['admin', 'user'],
          routes: [
            {
              path: '/',
              redirect: '/dashboard/analysis',
              icon: 'icon-wenjianfile63',
              name: '首页',
            },
            {
              path: '/dashboard',
              name: 'dashboard',
              icon: 'smile',
              routes: [
                {
                  name: 'analysis',
                  icon: 'smile',
                  path: '/dashboard/analysis',
                  component: './dashboard/analysis',
                }
              ],
            },
            {
              path: '/auth',
              name: 'auth', 
              routes: [
                {
                  path: '/auth/role',
                  name: 'role',
                  component: './auth/role',
                },
                {
                  path: '/auth/role/save',
                  name: 'role-save',
                  component: './auth/role/save',
                  hideInMenu:true
                },
                {
                  path: '/auth/menu',
                  name: 'menu',
                  component: './auth/menu',
                },
              ],
            },          
            {
              name: 'vip',
              path: '/vip',
              routes: [
                {
                  path: '/vip/center',
                  name: 'center',
                  component: './vip/center',
                },
                {
                  path: '/vip/center/save',
                  name: 'save',
                  component: './vip/center/save',
                  hideInMenu:true
                },
                {
                  path: '/vip/center/update/:id',
                  name: 'update',
                  component: './vip/center/update',
                  hideInMenu:true
                },
                {
                  path: '/vip/center/detail/:id',
                  name: 'detail',
                  component: './vip/center/detail',
                  hideInMenu:true
                },
                {
                  path: '/vip/center/body/save/:id',
                  name: 'save-body',
                  component: './vip/center/saveBody',
                  hideInMenu:true
                },
                {
                  path: '/vip/bind-card',
                  name: 'bind',
                  component: './vip/bind',
                },
                {
                  path: '/vip/bind-card/save',
                  name: 'save-bind',
                  component: './vip/bind/save',
                  hideInMenu:true
                },
                {
                  path: '/vip/bind-card/renew/:cardId/:memberId',
                  name: 'renew',
                  component: './vip/bind/oper/renew',
                  hideInMenu:true
                },
                {
                  path: '/vip/bind-card/deduction/:cardId/:memberId',
                  name: 'deduction',
                  component: './vip/bind/oper/deduction',
                  hideInMenu:true
                },
                {
                  path: '/vip/bind-card/stop/:cardId/:memberId',
                  name: 'stop',
                  component: './vip/bind/oper/stop',
                  hideInMenu:true
                },
                {
                  path: '/vip/bind-card/convert/:cardId/:memberId',
                  name: 'convert',
                  component: './vip/bind/oper/convert',
                  hideInMenu:true
                },
                {
                  path: '/vip/card',
                  name: 'card',
                  component: './vip/card',
                },
                {
                  path: '/vip/card/save',
                  name: 'save-card',
                  component: './vip/card/save',
                  hideInMenu:true
                },
                {
                  path: '/vip/card/update/:id',
                  name: 'update-card',
                  component: './vip/card/update',
                  hideInMenu:true
                },
                {
                  path: '/vip/card/detail/:cardId/:memberId',
                  name: 'cardDetail',
                  component: './vip/card/detail',
                  hideInMenu:true
                },
              ],
            },
            {
              name: 'shop',
              path: '/shop',
              routes: [
                {
                  path: '/shop/center',
                  name: 'center',
                  component: './shop/center',
                },
                {
                  path: '/shop/center/save',
                  name: 'save',
                  component: './shop/center/save',
                  hideInMenu:true
                },
                {
                  path: '/shop/center/update/:id',
                  name: 'update',
                  component: './shop/center/update',
                  hideInMenu:true
                },
              ],
            },
            {
              name: 'site',
              path: '/site',
              hideInMenu:true,
              routes: [
                {
                  path: '/site/center/:id',
                  name: 'center',
                  component: './site/center',
                  hideInMenu:true,
                },
                {
                  path: '/site/center/save/:id',
                  name: 'save',
                  component: './site/center/save',
                  hideInMenu:true
                },
                {
                  path: '/site/center/update/:id/:siteId',
                  name: 'update',
                  component: './site/center/update',
                  hideInMenu:true
                }
              ],
            },
            {
              name: 'lesson',
              path: '/lesson',
              routes: [
                {
                  path: '/lesson/schedule',
                  name: 'schedule',
                  component: './lesson/schedule',
                },
                {
                  path: '/lesson/schedule/edit/:id',
                  name: 'scheduleEdit',
                  component: './lesson/schedule/edit',
                },
                {
                  path: '/lesson/private',
                  name: 'private',
                  component: './lesson/private',
                },
                {
                  path: '/lesson/private/edit/:id',
                  name: 'privateEdit',
                  component: './lesson/private/edit',
                },
                {
                  path: '/lesson/private/save',
                  name: 'private-save',
                  component: './lesson/private/save',
                  hideInMenu:true
                },
                {
                  path: '/lesson/list',
                  name: 'list',
                  component: './lesson/list',
                  hideInMenu:true
                },
                {
                  path: '/lesson/list/save/:courseType',
                  name: 'save',
                  component: './lesson/list/save',
                  hideInMenu:true
                },
                {
                  path: '/lesson/list/update/:courseType/:id',
                  name: 'update',
                  component: './lesson/list/update',
                  hideInMenu:true
                },
                {
                  path: '/lesson/list/detail/:id',
                  name: 'detail',
                  component: './lesson/list/detail',
                },
                {
                  path:"/lesson/schedule/addSchedule",
                  name:"addSchedule",
                  component: './lesson/schedule/addSchedule',
                  hideInMenu:true
                },
              ],
            },
            {
              name: 'tag',
              path: '/tag',
              level:'1',
              routes: [
                {
                  path: '/tag/list',
                  name: 'list',
                  component: './tag/tag',
                 
                },
              ],
            },
            {
              name: 'employee',
              path: '/employee',
              level:'1',
              routes: [
                {
                  path: '/employee/list',
                  name: 'list',
                  component: './employee/employee',
                 
                },
                {
                  path: '/employee/list/save',
                  name: 'save',
                  component: './employee/employee/save',
                },
                {
                  path: '/employee/list/update/:id',
                  name: 'update',
                  component: './employee/employee/update',
                },
                {
                  path: '/employee/list/detail/:id',
                  name: 'detail',
                  component: './employee/employee/detail',
                },
                // {
                //   path: '/employee/coach',
                //   name: 'coach',
                //   component: './employee/coach',
                // },
                // {
                //   path: '/employee/coach/save',
                //   name: 'save',
                //   component: './employee/coach/save',
                // },
                // {
                //   path: '/employee/coach/update/:id',
                //   name: 'update',
                //   component: './employee/coach/update',
                // },
                // {
                //   path: '/employee/coach/detail/:id',
                //   name: 'detail',
                //   component: './employee/coach/detail',
                // },
              ],
            },
            {
              name: 'account',
              path: '/account',
              routes: [
                {
                  name: 'center',
                  path: '/account/center',
                  component: './account/center',
                },
                {
                  name: 'settings',
                  path: '/account/settings',
                  component: './account/settings',
                },
              ],
            },
            {
              name: 'sign',
              path: '/sign',
              level:'1',
              routes: [
                {
                  path: '/sign/reservation',
                  name: 'reservation',
                  component: './reservation',
                 
                }, 
                {
                  path: '/sign/signIn',
                  name: 'signIn',
                  component: './signIn',
                 
                },
                {
                  path: '/sign/reservation/detail/:id',
                  name: 'detail',
                  component: './reservation/detail',
                  hideInMenu:true
                }
              ],
            },
            {
              name: 'report',
              path: '/report',
              level:'1',
              routes: [
                {
                  path: '/report/day',
                  name: 'day',
                  component: './report/day',
                },
                {
                  path: '/report/pay',
                  name: 'pay',
                  component: './report/pay',
                },
                {
                  path: '/report/business',
                  name: 'business',
                  component: './report/business',
                },
                {
                  path: '/report/course/:userId',
                  name: 'course',
                  component: './report/course',
                  hideInMenu:true
                }
              ],
            },
            {
              name: 'stock',
              path: '/stock',
              level:'1',
              routes: [
                {
                  path: '/stock/giveaway',
                  name: 'giveaway',
                  component: './stock/giveaway',
                 
                },
                {
                  path: '/stock/report',
                  name: 'report',
                  component: './stock/report',
                },
                {
                  path: '/stock/report/:merchandiseId/:name',
                  name: 'report',
                  component: './stock/report',
                  hideInMenu:true
                },
              ],
            },
            {
              name: '薪酬',
              path: '/wage',
              level:'1',
              routes: [
                {
                  path: '/wage/setting',
                  name: 'settting',
                  component: './wage/setting',
                 
                }
              ],
            },
            {
              path: '/',
              redirect: '/dashboard/analysis',
              authority: ['admin', 'user'],
            },
            {
              component: '404',
            },
          ],
        },
      ],
    },
  ],
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // ...darkTheme,
    'primary-color': defaultSettings.primaryColor,
  },
  define: {
    REACT_APP_ENV: REACT_APP_ENV || false,
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION:
      ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION || '', // preview.pro.ant.design only do not use in your production ; preview.pro.ant.design 专用环境变量，请不要在你的项目中使用它。
  },
  ignoreMomentLocale: true,
  lessLoader: {
    javascriptEnabled: true,
  },
  cssLoader: {
    modules: {
      getLocalIdent: (context, _, localName) => {
        if (
          context.resourcePath.includes('node_modules') ||
          context.resourcePath.includes('ant.design.pro.less') ||
          context.resourcePath.includes('global.less')
        ) {
          return localName;
        }

        const match = context.resourcePath.match(/src(.*)/);

        if (match && match[1]) {
          const antdProPath = match[1].replace('.less', '');
          const arr = winPath(antdProPath)
            .split('/')
            .map(a => a.replace(/([A-Z])/g, '-$1'))
            .map(a => a.toLowerCase());
          return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
        }

        return localName;
      },
    },
  },
  manifest: {
    basePath: '/',
  },
  proxy: proxy[REACT_APP_ENV || 'dev'],
  chainWebpack: webpackPlugin,
});
